package jmine.tec.subscription.impl;

/**
 * {@link SubscriptionSetImpl} com timeout
 * 
 * @author takeshi
 */
public class ExpiringSubscriptionSetImpl extends SubscriptionSetImpl {

    private final long interval;

    private long nextTimeout;

    /**
     * @param interval long
     */
    public ExpiringSubscriptionSetImpl(long interval) {
        super();
        this.interval = interval;
        this.nextTimeout = System.currentTimeMillis() + interval;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public synchronized boolean isExpired() {
        return System.currentTimeMillis() > nextTimeout;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public synchronized void renewTimeout() {
        if (!isExpired()) {
            nextTimeout = System.currentTimeMillis() + interval;
        }
    }

    /**
     * {@inheritDoc}
     * 
     * @see jmine.tec.subscription.impl.SubscriptionSetImpl#nextTimeout()
     */
    @Override
    public long nextTimeout() {
        return this.nextTimeout;
    }

}
